{include file="public/head" /}
<style>.am-popup{height: 350px}.admin-main{padding-top:0}</style>
</head>
<body>
<div class="am-cf admin-main">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">基础信息管理</strong> / <small>专业管理</small></div>

            </div>

            <div class="am-u-md-10">
                <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <button type="button" class="am-btn am-btn-default" id="add"><span class="am-icon-plus"></span> 新增</button>
                    </div>
                </div>

                <table class="am-table am-table-bd am-table-striped admin-content-table">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>专业名称</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="rows" id="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.description}</td>
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="edit({$vo.id})"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="del(this,{$vo.id})"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <span>共{$rows->total()}条记录</span>
                <div class="pagination" style="float: right">{$page}</div>
            </div>
        </div>
    </div>
</div>
<!--添加用户模态框-->
<div class="am-popup" id="addModal">
    <div class="am-popup-inner">
        <div class="am-popup-hd">
            <h4 class="am-popup-title">添加专业</h4>
            <span data-am-modal-close class="am-close">&times;</span>
        </div>
        <div class="am-popup-bd">
            <form method="post" class="am-form" action="/admin/Major/addPost">
                <label>名称</label>
                <input type="text" name="name">
                <label>备注</label>
                <input type="text" name="description">
                <div class="am-cf">
                    <a class="am-btn am-btn-primary am-btn-sm am-fl ajax-submit" href="javascript:;">提交</a>
                </div>
            </form>
        </div>
    </div>
</div>
<!--编辑用户模态框-->
<div class="am-popup" id="editModal">
    <div class="am-popup-inner">
        <div class="am-popup-hd">
            <h4 class="am-popup-title">编辑专业</h4>
            <span data-am-modal-close
                  class="am-close">&times;</span>
        </div>
        <div class="am-popup-bd">
            <form method="post" class="am-form" action="/admin/Major/editPost">
                <label>名称</label>
                <input type="text" name="name">
                <label>备注</label>
                <input type="text" name="description">
                <div class="am-cf">
                    <input type="hidden" name="id">
                    <a class="am-btn am-btn-primary am-btn-sm am-fl ajax-submit" href="javascript:;">提交</a>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- content end -->
</div>
<script src="__STATIC__/js/ajax_form.js"></script>
<script>
    $(function(){
        $("#add").on("click",function(){
            $('#addModal').modal();
        });
    });
    function edit(id) {
        if(id == ''){
            layer.msg('参数获取失败,请刷新重试', {time: 1500, icon: 5});
            return false;
        }
        $.post("{:url('admin/Major/getDetail')}", {id: id}, function (res) {
            var detail = res.data;
            var editForm = $("#editModal").find("form");//获取编辑表单
            //表单赋值
            editForm.find("input[name='description']").val(detail.description);
            editForm.find("input[name='name']").val(detail.name);
            editForm.find("input[name='id']").val(detail.id);
        });
        $('#editModal').modal();
    }
    function del(self,id) {
        layer.confirm('确认要删除吗?', function (index) {
            $.post("{:url('admin/Major/delete')}", {id: id}, function (res) {
                if (res.code == 1) {
                    $(self).closest("tr").remove();//前端删除
                    layer.msg(res.msg, {time: 1500, icon: 6});
                } else {
                    layer.msg(res.msg, {time: 1500, icon: 5});
                }
            });
        });
    }

</script>
</body>
</html>
